﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using AMG.DALProfile;

namespace AMG.Web
{
    
    public partial class reging : AMG.Web.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //doreg(); 
            }
        }

        private void doreg()
        {
            try
            {
                AMG.Web.UI.Page.BasePage bp = new AMG.Web.UI.Page.BasePage();
                int UserID = bp.GetUserID();
                AMG.Model.AMG_UserInfo usinfo = new AMG.Model.AMG_UserInfo();
                AMG.Model.AMG_Proxy apinfo = new AMG.Model.AMG_Proxy();
                usinfo.UserName = Request.Form["name"];
                if (Request.Form["sex"] == "0")
                {
                    usinfo.Sex = false;
                }
                else if (Request.Form["sex"] == "1")
                {
                    usinfo.Sex = true;
                }
                usinfo.City = Request.Form["city"];
                usinfo.CustomerProperty = Request.Form["CustomerProperty"];
                usinfo.Company = Request.Form["company"];
                usinfo.Positison = Request.Form["Positison"];
                usinfo.CRNo = Request.Form["crno"];
                if (Request.Form["DriverLisecen"] == "0")
                {
                    usinfo.DriverLisecen = false;
                }
                else if (Request.Form["DriverLisecen"] == "1")
                {
                    usinfo.DriverLisecen = true;
                }
                usinfo.Phone = Request.Form["Phone"];
                usinfo.Address = Request.Form["Address"];
                usinfo.ZipCode = Request.Form["ZipCode"];
                usinfo.Mail = Request.Form["mail"];
                if (Request.Form["IsBook"] == "0")
                {
                    usinfo.IsBook = false;
                }
                else if (Request.Form["IsBook"] == "1")
                {
                    usinfo.IsBook = true;
                }
                usinfo.CarNo = int.Parse(Request.Form["carno"]);
                if (Request.Form["ArrivalDate"] == null || Request.Form["ArrivalDate"] == "")
                {
                    usinfo.ArrivalDate = null;
                }
                else
                {
                    usinfo.ArrivalDate = DateTime.Parse(Request.Form["ArrivalDate"]);
                }
                usinfo.ArrivalTraffic = int.Parse(Request.Form["ArrivalTraffic"]);
                usinfo.TrafficNo = Request.Form["TrafficNo"];
                usinfo.StartH = Request.Form["StartH"];
                usinfo.StartM = Request.Form["StartM"];
                usinfo.EndH = Request.Form["EndH"];
                usinfo.EndM = Request.Form["EndM"];
                usinfo.StartCity = Request.Form["StartCity"];
                if (Request.Form["NeedGet"] == "0")
                {
                    usinfo.NeedGet = false;
                }
                else if (Request.Form["NeedGet"] == "1")
                {
                    usinfo.NeedGet = true;
                }
                if (Request.Form["ReturnDate"] == null || Request.Form["ReturnDate"] == "")
                {
                    usinfo.ReturnDate = null;
                }
                else
                {
                    usinfo.ReturnDate = DateTime.Parse(Request.Form["ReturnDate"]);
                }
                usinfo.ReturnTraffic = int.Parse(Request.Form["ReturnTraffic"]);
                usinfo.TrafficNo1 = Request.Form["TrafficNo1"];
                usinfo.ReturnH = Request.Form["ReturnH"];
                usinfo.ReturnM = Request.Form["ReturnM"];
                usinfo.ReturnCity = Request.Form["ReturnCity"];
                if (Request.Form["NeedSend"] == "0")
                {
                    usinfo.NeedSend = false;
                }
                else if (Request.Form["NeedSend"] == "1")
                {
                    usinfo.NeedSend = true;
                }
                if (Request.Form["Room"] == "0")
                {
                    usinfo.Room = false;
                }
                else if (Request.Form["Room"] == "1")
                {
                    usinfo.Room = true;
                }
                if (Request.Form["Golf"] == "0")
                {
                    usinfo.Golf = false;
                }
                else if (Request.Form["Golf"] == "1")
                {
                    usinfo.Golf = true;
                }
                if (Request.Form["Equipment"] == "0")
                {
                    usinfo.Equipment = false;
                }
                else if (Request.Form["Equipment"] == "1")
                {
                    usinfo.Equipment = true;
                }
                usinfo.GolfTime = int.Parse(Request.Form["GolfTime"]);
                usinfo.CompanyID = UserID;
                AMG.DALSQLServer.AMG_Proxy ap = new AMG.DALSQLServer.AMG_Proxy();
                apinfo.Code = ap.GetModel(UserID).Code;
                usinfo.AMGCode = apinfo.Code + (int.Parse(DbHelper.ExecuteScalar(CommandType.Text, "select count(*) from AMG_UserInfo where CompanyID='" + UserID + "' ", null).ToString()) + 1).ToString("00");
                AMG.DALSQLServer.AMG_UserInfo us = new AMG.DALSQLServer.AMG_UserInfo();
                us.Add(usinfo);
                int userid = int.Parse(DbHelper.ExecuteScalar(CommandType.Text, "select ID from AMG_UserInfo where AMGCode ='"+ usinfo .AMGCode +"'", null).ToString());
                if (Request.Form["IsBook"] == "1")
                {
                    if (Request.Form["C63"] != null)
                    {
                        AMG.Model.AMG_Book bookinfo = new AMG.Model.AMG_Book();
                        AMG.DALSQLServer.AMG_Book ab = new AMG.DALSQLServer.AMG_Book();
                        bookinfo.CarID = 1;
                        bookinfo.UserID = userid;
                        ab.Add(bookinfo);
                    }
                    if (Request.Form["SLK55"] != null)
                    {
                        AMG.Model.AMG_Book bookinfo = new AMG.Model.AMG_Book();
                        AMG.DALSQLServer.AMG_Book ab = new AMG.DALSQLServer.AMG_Book();
                        bookinfo.CarID = 2;
                        bookinfo.UserID = userid;
                        ab.Add(bookinfo);
                    }
                    if (Request.Form["SL63"] != null)
                    {
                        AMG.Model.AMG_Book bookinfo = new AMG.Model.AMG_Book();
                        AMG.DALSQLServer.AMG_Book ab = new AMG.DALSQLServer.AMG_Book();
                        bookinfo.CarID = 3;
                        bookinfo.UserID = userid;
                        ab.Add(bookinfo);
                    }
                }
                if (Request.Form["carno"] != "0" && Request.Form["carno"] != null)
                {
                    cars(userid);
                }
            }
            catch
            {
                Response.Redirect("regfail.aspx",false);
            }
            Response.Write("<script>location.href=\"regok.aspx\"</script>");
        }

        private void cars(int userid)
        {
            if (Request.Form["carbland1"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland1"];
                carsinfo.CarName = Request.Form["carname1"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland2"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland2"];
                carsinfo.CarName = Request.Form["carname2"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland3"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland3"];
                carsinfo.CarName = Request.Form["carname3"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland4"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland4"];
                carsinfo.CarName = Request.Form["carname4"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland5"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland5"];
                carsinfo.CarName = Request.Form["carname5"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland6"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland6"];
                carsinfo.CarName = Request.Form["carname6"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland7"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland7"];
                carsinfo.CarName = Request.Form["carname7"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland8"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland8"];
                carsinfo.CarName = Request.Form["carname8"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland9"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland9"];
                carsinfo.CarName = Request.Form["carname9"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
            if (Request.Form["carbland10"] != null)
            {
                AMG.Model.AMG_Cars carsinfo = new AMG.Model.AMG_Cars();
                AMG.DALSQLServer.AMG_Cars ac = new AMG.DALSQLServer.AMG_Cars();
                carsinfo.CarBland = Request.Form["carbland10"];
                carsinfo.CarName = Request.Form["carname10"];
                carsinfo.UserID = userid;
                ac.Add(carsinfo);
            }
        }
    }
}
